package com.puzzlebazar.client.hashiwokakero;

import com.puzzlebazar.client.puzzle.model.Move;
import com.puzzlebazar.client.puzzle.model.MoveImpl;
import com.puzzlebazar.client.puzzle.model.PuzzleModel;
import com.puzzlebazar.client.util.Vec2i;

public abstract class MoveIsland extends MoveImpl {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4070844620994299840L;
	
	private Vec2i loc;
	private int   value;

	/**
	 * Only for serialization
	 */
	protected MoveIsland() {
		super();
	}
	
	/**
	 * A move that contains all the information required to create or delete an island
	 * 
	 * @param loc The location at which the island can be created/deleted
	 * @param value The value of the island
	 */
	public MoveIsland(Vec2i loc, int value) {
		super(-1);
		this.loc = loc;
		this.value = value;
	}

	/**
	 * @return The position at which the island was added or removed
	 */
	public Vec2i getLoc() {
		return loc;
	}

	/**
	 * @return The value of the added or removed island
	 */
	public int getValue() {
		return value;
	}		

	/**
	 * Create the island described in this move
	 * 
	 * @param model The model into which to create the island
     * @return A Move List that can be used for a more efficient call to notifyObserver()
	 * @throws Exception
	 */
	protected Move createIsland(PuzzleModel model) throws Exception {
		assert model instanceof HashiwokakeroModel;
		return ((HashiwokakeroModel)model).addIsland( getLoc(), getValue() );
	}
	
	/**
	 * Deletes the island described in this move
	 * 
	 * @param model The model from which to delete the island
     * @return A Move List that can be used for a more efficient call to notifyObserver()
	 * @throws Exception
	 */
	protected Move deleteIsland(PuzzleModel model) throws Exception {
		assert model instanceof HashiwokakeroModel;
		return ((HashiwokakeroModel)model).removeIsland(getLoc());		
	}
}
